<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no">
    <title>活动管理</title>
    <link href="https://fonts.googleapis.com/css?family=Nunito:400,600,700" rel="stylesheet">
    <link th:href="@{/bootstrap/css/bootstrap.min.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/assets/css/plugins.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/assets/css/forms/theme-checkbox-radio.css}" rel="stylesheet" type="text/css" >
    <link th:href="@{/plugins/jquery-ui/jquery-ui.min.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/assets/css/apps/contacts.css}" rel="stylesheet" type="text/css" />

    <link th:href="@{/plugins/flatpickr/custom-flatpickr.css}" rel="stylesheet" type="text/css">
    <link th:href="@{/plugins/flatpickr/flatpickr.css}" rel="stylesheet" type="text/css">


    <link th:href="@{/plugins/sweetalerts/sweetalert2.min.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/plugins/sweetalerts/sweetalert.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/assets/css/components/custom-sweetalert.css}" rel="stylesheet" type="text/css" />

    <link th:href="@{/plugins/notification/snackbar/snackbar.min.css}" rel="stylesheet" type="text/css" />
    <style>
        .w-info h6 {
            font-weight: 600;
            margin-bottom: 0;
            color: #0e1726;
            font-size: 23px;
            letter-spacing: 0;
        }

        .w-info p {
            font-weight: 600;
            margin-bottom: 0;
            color: #5c1ac3;
            font-size: 16px;
        }

        .user-email h4 {
            margin-left: 3.4375rem !important;
        }

        .menu {
            color: #888ea8 !important;
            height: 50px;
            line-height: 50px;
        }

        .user-meta-info {
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .user-meta-info p {
            margin-bottom: 0;
        }
        .user-meta-info {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 70%;
        }

        .user-meta-info p {
            margin-bottom: 0;
            width: 100%;
        }

        .user-email h4 {
            margin-left: 0 !important;
        }

        .searchable-container .searchable-items.list .items .item-content>div {
            width: 20%;
            text-align: center;
        }

        .searchable-container .searchable-items.list .items .item-content>div:first-child {
            width: 20%;
            text-align: left;
            flex-shrink: 0;
        }
    </style>
</head>

<body class="alt-menu sidebar-noneoverflow">

    <!--  头部  -->
    <div class="header-container fixed-top">
        <header class="header navbar navbar-expand-sm expand-header">
            <a href="javascript:void(0);" class="sidebarCollapse" data-placement="bottom"><svg
                    xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
                    stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                    class="feather feather-menu">
                    <line x1="3" y1="12" x2="21" y2="12"></line>
                    <line x1="3" y1="6" x2="21" y2="6"></line>
                    <line x1="3" y1="18" x2="21" y2="18"></line>
                </svg></a>

            <ul class="navbar-item flex-row ml-auto">
                <li class="nav-item dropdown user-profile-dropdown  order-lg-0 order-1">
                    <a href="javascript:void(0);" class="nav-link dropdown-toggle user" id="userProfileDropdown"
                       data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
                             stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                             class="feather feather-user-check">
                            <path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                            <circle cx="8.5" cy="7" r="4"></circle>
                            <polyline points="17 11 19 13 23 9"></polyline>
                        </svg>
                    </a>
                    <div class="dropdown-menu position-absolute e-animated e-fadeInUp"
                         aria-labelledby="userProfileDropdown">
                        <div class="user-profile-section">
                            <div class="media mx-auto">
                                <img th:src="@{/assets/img/avatar.png}" class="img-fluid mr-2" alt="avatar">
                                <div class="media-body">
                                    <h5>[[${admin.username}]]</h5>
                                </div>
                            </div>
                        </div>
                        <div class="dropdown-item">
                            <a href="/admin/userinfo">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-user">
                                    <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                                    <circle cx="12" cy="7" r="4"></circle>
                                </svg> <span>个人信息</span>
                            </a>
                        </div>
                        <div class="dropdown-item">
                            <a href="/admin/out">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-log-out">
                                    <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
                                    <polyline points="16 17 21 12 16 7"></polyline>
                                    <line x1="21" y1="12" x2="9" y2="12"></line>
                                </svg> <span>退出登录</span>
                            </a>
                        </div>
                    </div>
                </li>
            </ul>
        </header>
    </div>
    <!--  END 头部  -->

    <!--  BEGIN MAIN CONTAINER  -->
    <div class="main-container sidebar-closed sbar-open" id="container">

        <div class="overlay"></div>
        <div class="cs-overlay"></div>
        <div class="search-overlay"></div>

        <!--  BEGIN SIDEBAR  -->
        <div class="sidebar-wrapper sidebar-theme">

            <nav id="sidebar">

                <ul class="navbar-nav theme-brand flex-row  text-center">
                </ul>

                <ul class="list-unstyled menu-categories" id="accordionExample">
                    <li class="menu">
                        <a href="/admin" aria-expanded="true" class="dropdown-toggle">
                            <div class="">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-home">
                                    <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
                                    <polyline points="9 22 9 12 15 12 15 22"></polyline>
                                </svg>
                                <span>首页</span>
                            </div>
                        </a>
                    </li>
                    <li class="menu " th:if="${admin.type < 2}">
                        <a href="/admin/appsContacts" aria-expanded="true" class="dropdown-toggle">
                            <div class="">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-layout">
                                    <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
                                    <line x1="3" y1="9" x2="21" y2="9"></line>
                                    <line x1="9" y1="21" x2="9" y2="9"></line>
                                </svg>
                                <span>团队管理</span>
                            </div>
                        </a>
                    </li>
                    <li class="menu active" th:if="${admin.type < 2}">
                        <a href="/admin/activityList" aria-expanded="true" class="dropdown-toggle">
                            <div class="">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-box">
                                    <path
                                            d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z">
                                    </path>
                                    <polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
                                    <line x1="12" y1="22.08" x2="12" y2="12"></line>
                                </svg>
                                <span>活动管理</span>
                            </div>
                        </a>
                    </li>
                    <li class="menu">
                        <a href="/admin/userinfo" aria-expanded="true" class="dropdown-toggle">
                            <div class="">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-user">
                                    <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                                    <circle cx="12" cy="7" r="4"></circle>
                                </svg>
                                <span>个人信息</span>
                            </div>
                        </a>
                    </li>
                    <li class="menu">
                        <a href="/admin/personInfo" aria-expanded="true" class="dropdown-toggle">
                            <div class="">
                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                                     stroke-linejoin="round" class="feather feather-users">
                                    <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                                    <circle cx="9" cy="7" r="4"></circle>
                                    <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
                                    <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
                                </svg>
                                <span>客户信息</span>
                            </div>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <!--  END SIDEBAR  -->

        <!--  BEGIN CONTENT AREA  -->
        <div id="content" class="main-content">
            <div class="layout-px-spacing">
                <div class="row layout-spacing layout-top-spacing" id="cancel-row">
                    <div class="col-lg-12">
                        <div class="widget-content searchable-container list">
                            <div class="row">
                                <div
                                    class="col-xl-4 col-lg-5 col-md-5 col-sm-7 filtered-list-search layout-spacing align-self-center">
                                    <form class="form-inline my-2 my-lg-0">
                                        <div class=""
                                            style="display: flex;justify-content: space-between; padding: 0 10px;">
                                            <div class="w-info">
                                                <p class="">活动开展数</p>
                                                <h6 class="value">[[${num}]]</h6>
                                            </div>
                                            <div class="w-info">
                                                <p class="">当前进行的活动</p>
                                                <h8 class="value">[[${activityName}]]</h8>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <div
                                    class="col-xl-8 col-lg-7 col-md-7 col-sm-5 text-sm-right text-center layout-spacing align-self-center">
                                    <div class="d-flex justify-content-sm-end justify-content-center">
                                        <svg id="btn-add-contact" xmlns="http://www.w3.org/2000/svg" width="24"
                                            height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                                            stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                                            class="feather feather-user-plus">
                                            <path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
                                            <circle cx="8.5" cy="7" r="4"></circle>
                                            <line x1="20" y1="8" x2="20" y2="14"></line>
                                            <line x1="23" y1="11" x2="17" y2="11"></line>
                                        </svg>

                                        <div class="switch align-self-center">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                                stroke-linecap="round" stroke-linejoin="round"
                                                class="feather feather-list view-list active-view">
                                                <line x1="8" y1="6" x2="21" y2="6"></line>
                                                <line x1="8" y1="12" x2="21" y2="12"></line>
                                                <line x1="8" y1="18" x2="21" y2="18"></line>
                                                <line x1="3" y1="6" x2="3" y2="6"></line>
                                                <line x1="3" y1="12" x2="3" y2="12"></line>
                                                <line x1="3" y1="18" x2="3" y2="18"></line>
                                            </svg>
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                                stroke-linecap="round" stroke-linejoin="round"
                                                class="feather feather-grid view-grid">
                                                <rect x="3" y="3" width="7" height="7"></rect>
                                                <rect x="14" y="3" width="7" height="7"></rect>
                                                <rect x="14" y="14" width="7" height="7"></rect>
                                                <rect x="3" y="14" width="7" height="7"></rect>
                                            </svg>
                                        </div>
                                    </div>

                                    <!-- add弹窗-->
                                    <div class="modal fade" id="addContactModal" tabindex="-1" role="dialog"
                                        aria-labelledby="addContactModalTitle" aria-hidden="true">
                                        <div class="modal-dialog modal-dialog-centered" role="document">
                                            <div class="modal-content">
                                                <div class="modal-body">
                                                    <i class="flaticon-cancel-12 close" data-dismiss="modal"></i>
                                                    <div class="add-contact-box">
                                                        <div class="add-contact-content">
                                                            <form id="addContactModalTitle">
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <div class="contact-name">
                                                                            <i class="flaticon-user-11"></i>
                                                                            <p style="text-align:left!important">活动名称:
                                                                            </p>
                                                                            <input type="text" class="form-control" id="exampleFormControlInput1"
                                                                                   value="" placeholder="请输入活动名称">
                                                                            <span class="validation-text"></span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <div class="contact-name">
                                                                            <i class="flaticon-user-11"></i>
                                                                            <p style="text-align:left!important">开始时间:
                                                                            </p>
                                                                            <input id="basicFlatpickr" value=""
                                                                                   class="form-control flatpickr flatpickr-input active" type="text"
                                                                                   placeholder="请选择开始时间">
                                                                            <span class="validation-text"></span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="row">
                                                                    <div class="col-md-12">
                                                                        <div class="contact-name">
                                                                            <i class="flaticon-user-11"></i>
                                                                            <p style="text-align:left!important">结束时间:
                                                                            </p>
                                                                            <input id="basicFlatpickr1" value=""
                                                                                   class="form-control flatpickr1 flatpickr-input active" type="text"
                                                                                   placeholder="请选择结束时间">
                                                                            <span class="validation-text"></span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="row pwd">
                                                                    <div class="col-md-12">
                                                                        <div class="contact-occupation">
                                                                            <i class="flaticon-fill-area"></i>
                                                                            <p style="text-align:left!important">礼品数量:
                                                                            </p>
                                                                            <input type="number" class="form-control" id="exampleFormControlInput4"
                                                                                   value="" placeholder="礼品数量">
                                                                            <span class="validation-text"></span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button id="btn-edit" class="float-left btn" >保存</button>
                                                    <button class="btn" data-dismiss="modal" onclick="cancelActivity()"> <i
                                                            class="flaticon-delete-1" ></i> 取消</button>
                                                    <button id="btn-add" class="btn" onclick="creatActivity(0,0)">创建活动</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="searchable-items list">
                                <div class="items items-header-section">
                                    <div class="item-content">
                                        <div class="">
                                            <div class="n-chk align-self-center text-center">
                                                <label class="new-control new-checkbox checkbox-primary">
                                                    <input type="checkbox" class="new-control-input"
                                                        id="contact-check-all">
                                                    <span class="new-control-indicator"></span>
                                                </label>
                                            </div>
                                            <h4>ID</h4>
                                        </div>

                                        <div class="user-email">
                                            <h4>活动名称</h4>
                                        </div>
                                        <div class="user-email">
                                            <h4>开始时间</h4>
                                        </div>
                                        <div class="user-location">
                                            <h4 style="margin-left: 0;">结束时间</h4>
                                        </div>
                                        <div class="user-phone">
                                            <h4 style="margin-left: 3px;">礼品数量</h4>
                                        </div>
                                        <div class="action-btn">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
                                                stroke-linecap="round" stroke-linejoin="round"
                                                class="feather feather-trash-2  delete-multiple">
                                                <polyline points="3 6 5 6 21 6"></polyline>
                                                <path
                                                    d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2">
                                                </path>
                                                <line x1="10" y1="11" x2="10" y2="17"></line>
                                                <line x1="14" y1="11" x2="14" y2="17"></line>
                                            </svg>
                                        </div>
                                    </div>
                                </div>

                                <!-- 数据循环开始-->
                                    <div class="items" th:each="list:${list}">
                                        <div class="item-content">
                                            <div class="user-profile">
                                                <div class="n-chk align-self-center text-center">
                                                    <label class="new-control new-checkbox checkbox-primary">
                                                        <input type="checkbox" class="new-control-input contact-chkbox">
                                                        <span class="new-control-indicator"></span>
                                                    </label>
                                                </div>
                                                <div class="img"></div>
                                                <div class="user-meta-info" style="line-height:44px">
                                                    <p style="text-align:left!important">ID:</p >
                                                    <p class="user-card" data-id="${list.id}">[(${list.id})] </p>
                                                </div>
                                            </div>
                                            <input th:id="${'activityName-'+list.id}" th:value="${list.activityName}" hidden="hidden">
                                            <input th:id="${'startTime-'+list.id}" th:value="${list.startTime}" hidden="hidden">
                                            <input th:id="${'endTime-'+list.id}" th:value="${list.endTime}" hidden="hidden">
                                            <input th:id="${'gift-'+list.id}"th:value="${list.gift}" hidden="hidden">
                                            <input th:id="${'state-'+list.id}"th:value="${list.state}" hidden="hidden">

                                            <div class="user-location">
                                                <p class="info-title">活动名称:</p >
                                                <p>[(${list.activityName})]</p>
                                            </div>
                                            <div class="user-email">
                                                <p class="info-title">开始时间:</p >
                                                <p th:text="${#dates.format(list.startTime,'yyyy-MM-dd HH:mm:ss')}"></p>
                                            </div>
                                            <div class="user-location">
                                                <p class="info-title">结束时间:</p >
                                                <p th:text="${#dates.format(list.endTime,'yyyy-MM-dd HH:mm:ss')}"></p>
                                            </div>
                                            <div class="user-location">
                                                <p class="info-title">礼品数量:</p >
                                                <p>[(${list.gift})]</p>
                                            </div>
                                            <div class="action-btn">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-2" th:onclick="editActivity([[${list.id}]])"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg>

                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user-minus" th:onclick="delActivity([[${list.id}]])"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="23" y1="11" x2="17" y2="11"></line></svg>
                                            </div>
                                        </div>
                                    </div>
<!--                                数据循环结束-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--  END CONTENT AREA  -->
    </div>
    <!-- END MAIN CONTAINER -->

    <script th:src="@{/assets/js/libs/jquery-3.1.1.min.js}"></script>
    <script th:src="@{/bootstrap/js/popper.min.js}"></script>
    <script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/plugins/perfect-scrollbar/perfect-scrollbar.min.js}"></script>
    <script th:src="@{/assets/js/app.js}"></script>
    <script th:src="@{/assets/js/custom.js}"></script>
    <script th:src="@{/plugins/jquery-ui/jquery-ui.min.js}"></script>
    <script th:src="@{/assets/js/apps/contact.js}"></script>
    <script th:src="@{/plugins/flatpickr/flatpickr.js}"></script>
    <script th:src="@{/plugins/flatpickr/custom-flatpickr.js}"></script>
    <script th:src="@{/plugins/notification/snackbar/snackbar.min.js}"></script>



    <!-- BEGIN THEME GLOBAL STYLE -->
    <script th:src="@{/assets/js/scrollspyNav.js}"></script>
    <script th:src="@{/plugins/sweetalerts/sweetalert2.min.js}"></script>
    <script th:src="@{/plugins/sweetalerts/custom-sweetalert.js}"></script>
    <!-- END THEME GLOBAL STYLE -->
    <script>
        $(document).ready(function () {
            App.init();
        });
        function editActivity(i) {

            var state = $("#state-"+i).val();
            if (state==1){
                Snackbar.show({
                    text: "活动已结束，禁止修改",
                    pos: 'top-center'
                });
                return false;
            }
            $('#addContactModal #btn-add').hide();
            $('#addContactModal #btn-edit').show();
            $('#addContactModal #btn-edit').attr("onclick","creatActivity(1,"+i+")");

            $('#exampleFormControlInput1').val($("#activityName-"+i).val())
            $('#basicFlatpickr').val($("#startTime-"+i).val())
            $('#basicFlatpickr1').val($("#endTime-"+i).val())
            $('#exampleFormControlInput4').val($("#gift-"+i).val())

            $('#addContactModal').modal('show');
        }
        function delActivity(i) {
            swal({
                title: '确定删除吗?',
                text: "删除后不能恢复！",
                type: 'warning',
                showCancelButton: true,
                cancelButtonText:
                    '<i class="flaticon-cancel-circle"></i> 取消',
                confirmButtonText: '确定',
                padding: '2em'
            }).then(function(result) {
                if (result.value) {
                    $.ajax({
                        url: "/admin/delActivity",
                        method: "POST",
                        data : {id:i},
                        success: function (result) {
                            if(result.code == "500"){
                                Snackbar.show({
                                    text: result.msg,
                                    pos: 'top-center'
                                });
                                $('#addContactModal').modal('hide');
                            }else if(result.code == "200"){
                                Snackbar.show({
                                    text: result.msg,
                                    pos: 'top-center'
                                });
                                $('#addContactModal').modal('hide');
                                setTimeout(function (){
                                    window.location.reload();
                                }, 1500);
                            }else if(result.code == "100"){
                                Snackbar.show({
                                    text: "您已掉线！",
                                    pos: 'top-center'
                                });
                                setTimeout(function (){
                                    window.location.href="/admin/login";
                                }, 1500);
                            }
                        },
                        error : function() {
                            Snackbar.show({
                                text: '请稍后再试',
                                pos: 'top-center'
                            });
                            setTimeout(function (){
                                window.location.reload();
                            }, 1500);
                        }
                    })
                }
            })
        }
        function cancelActivity() {
            $('#exampleFormControlInput1').val("")
            $('#basicFlatpickr').val("")
            $('#basicFlatpickr1').val("")
            $('#exampleFormControlInput4').val("")
            $('#addContactModal').modal('hide');
        }

        Date.prototype.format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o){
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        }

        function creatActivity(type,i) {
                var activeName = $('#exampleFormControlInput1').val()
                var startTime = $('#basicFlatpickr').val()
                var endTime = $('#basicFlatpickr1').val()
                var num = $('#exampleFormControlInput4').val()
                if(activeName == ""){
                    Snackbar.show({
                        text: "请填写活动名称",
                        pos: 'top-center'
                    });
                    return false;
                }
                if(startTime == ""){
                    Snackbar.show({
                        text: "请选择活动开始时间",
                        pos: 'top-center'
                    });
                    return false;
                }
                if(endTime == ""){
                    Snackbar.show({
                        text: "请选择活动结束时间",
                        pos: 'top-center'
                    });
                    return false;
                }
                if(num == ""){
                    Snackbar.show({
                        text: "请填写礼品数量",
                        pos: 'top-center'
                    });
                    return false;
                }


                var data;
                data= {
                    activityName : activeName,
                    startTime :new Date(startTime+" 00:00:00").format("yyyy-MM-dd hh:mm:ss"),
                    endTime :new Date(endTime+" 23:59:59").format("yyyy-MM-dd hh:mm:ss"),
                    gift :num
                }
                var postUrl = "/admin/createActive";
                if(type ==1){
                    console.log(new Date(startTime).getTime())
                    postUrl = "/admin/updateActive";
                    data= {
                        id : i,
                        activityName : activeName,
                        startTime :new Date(startTime+" 00:00:00").format("yyyy-MM-dd hh:mm:ss"),
                        endTime :new Date(endTime+" 23:59:59").format("yyyy-MM-dd hh:mm:ss"),
                        gift :num
                    }
                }
                $.ajax({
                    url: postUrl,
                    method: "POST",
                    data : data,
                    success: function (result) {
                        if(result.code == "500"){
                            Snackbar.show({
                                text: result.msg,
                                pos: 'top-center'
                            });
                            $('#addContactModal').modal('hide');
                        }else if(result.code == "200"){
                            Snackbar.show({
                                text: result.msg,
                                pos: 'top-center'
                            });
                            $('#addContactModal').modal('hide');
                            setTimeout(function (){
                                window.location.reload();
                            }, 1500);
                        }else if(result.code == "100"){
                            Snackbar.show({
                                text: "您已掉线！",
                                pos: 'top-center'
                            });
                            setTimeout(function (){
                                window.location.href="/admin/login";
                            }, 1500);
                        }
                    },
                    error : function() {
                        Snackbar.show({
                            text: '请稍后再试',
                            pos: 'top-center'
                        });
                    }
                })
        }
    </script>
</body>

</html>